<?php

/**
 * 微信扫描来源
 */
namespace backend\controllers;

use bc\controller\BackendController;
use bc\util\backend\Page;
use bc\model\wx\QrcodeModel;
use bc\model\qrcode\ScanModel;

class QrcodeController extends BackendController
{
	
	
	public function actionIndex()
	{
		$model = new QrcodeModel();
		
		$params['type'] = 'qr';
		
		$page = $this->get('page', 1);
		$model->sort = 'qid DESC';
		$list = $model->getList($params, $page, self::PAGE_SIZE);
		
		$total = $model->getTotal($params);
		
		$pagination = new Page($total, self::PAGE_SIZE);
		
		$view['list'] = $list;
		$view['pagination'] = $pagination;
		
		return $this->render('index', $view);
	}
	
	public function actionEdit()
	{
		$id = $this->get('id');
		if(!$id)
			$this->redirect('/');
	
		$model = new QrcodeModel();
		$rowParams['qid'] = $id;
		$row = $model->getRow($rowParams);
		
		$date_time = $this->get('date_time');
		
		$scanModel = new ScanModel();
		
		
		if(!$row)
			$this->redirect('/');
			
		$params['scene_id'] = $row['qid'];
		
		
		if($date_time)
		{
			$params['create_time'] = strtotime($date_time);
		}
		
		$view['row'] = $row;
		
		$page = $this->get('page', 1);
		$scanModel->sort = 'id DESC';
		$list = $scanModel->getList($params, $page, self::PAGE_SIZE);
		
		$total = $scanModel->getTotal($params);
		
		$pagination = new Page($total, self::PAGE_SIZE);
		
		$view['list'] = $list;
		$view['pagination'] = $pagination;
		$view['date_time'] = $date_time;
		return $this->render('edit', $view);
	}
	
}

